package com.cykj.eurekaclient.service.impl;

import com.cykj.eurekaclient.bean.BackUser;
import com.cykj.eurekaclient.bean.DriverSalaryRecord;
import com.cykj.eurekaclient.bean.DriverSchedule;
import com.cykj.eurekaclient.mapping.DriverMapper;
import com.cykj.eurekaclient.service.DriverService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DriverServiceImpl implements DriverService {

    @Autowired
    private DriverMapper driverMapper;

    @Override
    public BackUser login(String account, String password, String phone) {
        return driverMapper.login(account, password, phone);
    }

    @Override
    public List<DriverSalaryRecord> salaryList(int driverId, RowBounds rowBounds, String date) {
        return driverMapper.salaryList(driverId, rowBounds, date);
    }

    @Override
    public int salaryRecord(int driverId) {
        int data = driverMapper.salaryRecord(driverId);
        int totalPage;
        if(data % 10 == 0){
            totalPage = data / 10;
        }else{
            totalPage = data / 10 + 1;
        }
        return totalPage;
    }

    @Override
    public List<DriverSchedule> recordList(int driverId, RowBounds rowBounds, String startDate, String endDate) {
        return driverMapper.recordList(driverId, rowBounds, startDate, endDate);
    }

    @Override
    public int departureRecord(int driverId) {
        int data = driverMapper.departureRecord(driverId);
        int totalPage;
        if(data % 10 == 0){
            totalPage = data / 10;
        }else{
            totalPage = data / 10 + 1;
        }
        return totalPage;
    }

    @Override
    public List<DriverSchedule> timeList(int driverId, RowBounds rowBounds, String startDate, String endDate) {
        return driverMapper.timeList(driverId, rowBounds, startDate, endDate);
    }

    @Override
    public int timeTable(int driverId) {
        int data = driverMapper.timeTable(driverId);
        int totalPage;
        if(data % 10 == 0){
            totalPage = data / 10;
        }else{
            totalPage = data / 10 + 1;
        }
        return totalPage;
    }

    @Override
    public List<DriverSchedule> workload(int driverId, RowBounds rowBounds, String startDate, String endDate) {
        return driverMapper.workload(driverId, rowBounds, startDate, endDate);
    }

    @Override
    public int workloadRecord(int driverId) {
        int data = driverMapper.workloadRecord(driverId);
        int totalPage;
        if(data % 10 == 0){
            totalPage = data / 10;
        }else{
            totalPage = data / 10 + 1;
        }
        return totalPage;
    }

    @Override
    public List<DriverSchedule> checkList(int driverId, String date, String time) {
        return driverMapper.checkList(driverId, date, time);
    }

    @Override
    public List<DriverSchedule> busList(int driverId, String date, String time, String nearTime) {
        return driverMapper.busList(driverId, date, time, nearTime);
    }

    @Override
    public boolean departure(int driverId, int id) {
        boolean flag;
        try{
           driverMapper.departure(driverId, id);
           flag = true;
        }catch (Exception e){
            flag = false;
        }
        return flag;
    }

    @Override
    public List<DriverSalaryRecord> deductionList(int driverId, RowBounds rowBounds, String startDate, String endDate) {
        return driverMapper.deductionList(driverId, rowBounds, startDate, endDate);
    }

    @Override
    public int deductionRecord(int driverId) {
        int data = driverMapper.deductionRecord(driverId);
        int totalPage;
        if(data % 10 == 0){
            totalPage = data / 10;
        }else{
            totalPage = data / 10 + 1;
        }
        return totalPage;
    }

    @Override
    public List<DriverSchedule> schedules(int driverId) {
        return driverMapper.schedules(driverId);
    }

    @Override
    public boolean leave(int driverId, String date) {
        boolean flag;
        try{
            driverMapper.leave(driverId, date);
            flag = true;
        }catch (Exception e){
            flag = false;
        }
        return flag;
    }
}
